package org.rbreznak.tronco.sql;

import java.util.ArrayList;
import java.util.Iterator;

public class SQLData implements Iterator{
	private ArrayList rows;
	private ArrayList<String> titles;
	private int curRow=0;
	
	public SQLData setData(ArrayList dat) {
		this.rows = dat;
		return this;
	}
	
	public int numRows() {
		return rows.size();
	}
	
	public boolean hasNext() {
		if(rows.isEmpty()) return false;
		return !(rows.size() == curRow);
	}

	public Object next() {
		if(hasNext()) {
			Object x = rows.get(curRow);
			this.curRow++;
			return x;
		}
		return null;
	}
	
	public String getTitle(int index) {
		if(index < 0 || index > (titles.size() - 1)) return null;
		return titles.get(index);
	}
	
	public ArrayList getResults() {
		return rows;
	}
	
	class SQLDataException extends Exception {

		private static final long serialVersionUID = 1L;
		String mistake;

		  public SQLDataException()
		  {
		    super();             // call superclass constructor
		    mistake = "unknown";
		  }

		  public SQLDataException(String err)
		  {
		    super(err);     // call super class constructor
		    mistake = err;  // save message
		  }
		  
		  public String getError()
		  {
		    return mistake;
		  }
	}

	public void remove() {
		// TODO Auto-generated method stub
		
	}
	
}
